﻿using FreeSql;
using NPOI.OpenXmlFormats.Encryption;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZoneLineNew.Common;
using ZoneLineNew.Models.Entity.User;
using ZoneLineNew.Services.DB;

namespace ZoneLineNew.Core.Helpers
{
    /// <summary>
    /// 数据库辅助类
    /// </summary>
    public class DBHelper
    {
        /// <summary>
        /// 创建数据
        /// </summary>
        public static void CraeteData()
        {
            List<UserEntity> UserEntityList = new List<UserEntity>();
            UserEntityList.Add(new UserEntity() {
                Account = "SuperAdmin",
                PassWord = "be8cf406cad03b7b87cba0fb4a6350e2",//ksroot0987
                Name = "SuperAdmin",
                IsAdmin = true,
                Rank = Enums.eRoleTypeEnum.SuperAdmin,
                CreatedTime = DateTime.Now,
                Status = true,
                Soft = 1
            });
            UserEntityList.Add(new UserEntity() {
                Account = "ProductionOperator",
                PassWord = "c6f3ea997a43406bc7677194b5a78ab1",//xj142536
                Name = "ProductionOperator",
                IsAdmin = false,
                Rank = Enums.eRoleTypeEnum.ProductionOperator,
                CreatedTime = DateTime.Now,
                Status = true,
                Soft = 2
            });
            UserEntityList.Add(new UserEntity() {
                Account = "PackingOperator",
                PassWord = "1c7d744a61e08df941ddb275aac59c75",//xj123456
                Name = "PackingOperator",
                IsAdmin = false,
                Rank = Enums.eRoleTypeEnum.PackingOperator,
                CreatedTime = DateTime.Now,
                Status = true,
                Soft = 3
            });
            var dbContext = PrismIocInfo.GetInstanceByIoc<IDbOperate<IFreeSqlMainContext>>();
            foreach (var userEntity in UserEntityList) {
                if (!dbContext.CheckExist<UserEntity>(o=>o.Account == userEntity.Account)) {
                    dbContext.AddModel(userEntity);
                }
            }
            LogManager.Info("初始化用户成功！");
        }


    }
}
